import { configureStore, combineReducers } from '@reduxjs/toolkit';
import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";
import tokenSlice from './token';
import darksSlice from './darks';

// configureStore创建一个redux数据
const rootReducer = combineReducers({
    token: tokenSlice,
    darksSlice: darksSlice
});
// 持久化配置
const persistConfig = {
    key: "root",
    storage,
    whitelist: ['token','darksSlice'], // 白名单，只持久化指定reducer的状态
};
const persistedReducer = persistReducer(persistConfig, rootReducer);
const store = configureStore({
    reducer: persistedReducer,
    devTools: true, // 是否开启开发者工具，默认true
    // 配置中间件：如果使用redux-persist，则需要设置为false，否则控制台报错（非序列化数据）
    middleware: (getDefaultMiddleware) => getDefaultMiddleware({
         serializableCheck: false,
    })
});
export const persistor = persistStore(store);

export default store